package com.gcalsync.component;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/**
 * @author Thomas Oldervoll, thomas@zenior.no
 * @author $Author$
 * @version $Rev: 24 $
 * @date $Date$
 */
public class OptionsComponent extends MVCComponent {

    List menu;
	MVCComponent nextDisplay;


    public Displayable getDisplayable() {
        return menu;
    }

    protected void initModel() {
    }

    protected void createView() {
        menu = new List("Options menu", List.IMPLICIT);
        menu.append("Sync period", null);
        menu.append("Time zone", null);
        menu.append("Upload/download", null);
		menu.append("Reset options", null);
        Command cancelCommand = new Command("Cancel", Command.CANCEL, 2);
        menu.addCommand(cancelCommand);
        menu.setCommandListener(this);
    }

    protected void updateView() {
    }

	public void showScreen(MVCComponent nextDisplayable)
	{
		nextDisplay = nextDisplayable;
		showScreen();
	}

    public void commandAction(Command command, Displayable displayable) {
        if (command.getCommandType() == Command.CANCEL) {

			if (nextDisplay == null) 
				Components.login.showScreen(false);
			else
				nextDisplay.showScreen(false);

        } else if (command == List.SELECT_COMMAND) {
            int choice = menu.getSelectedIndex();
            switch (choice) {
                case 0:
                    Components.period.handle();
                    break;
                case 1:
                    Components.timeZone.handle();
                    break;
                case 2:
                    Components.uploadDownload.handle();
                    break;
				case 3:
					Components.resetOptions.handle();
					break;
            }
        }
    }

}
